package cn.wawi.utils;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import jodd.http.HttpRequest;
import jodd.http.HttpResponse;

/**
 * @description jodd邮件发送
 * @author 龚亮
 * @datetime 2015-05-28 10:13:14
 */
public class EmailUtil {
	public static void main(String[] args) throws Exception {
		//sendQQMail();
		//get();
		post();
	}
//	public static void sendQQMail(){  
//        Email email = Email.create()  
//                .from("411400580@qq.com")  
//                .to("18602517465@163.com")  
//                .subject("testQQ")  
//                .addText("hello!")  
//                .addHtml("<html><META http-equiv=Content-Type content=\"text/html; charset=utf-8\">" +  
//                 "<body><h1>hello world!</h1></body></html>");  
//  
//                SendMailSession mailSession =   
//                        new SmtpSslServer("smtp.qq.com").authenticateWith("411400580@qq.com", "@a6278737")  
//                            .createSession();  
//                mailSession.open();  
//                mailSession.sendMail(email);  
//                mailSession.close();  
//                System.out.println("发送QQ成功!...");  
//    }  
	/**
	 * 发送get请求
	 * @throws Exception 
	 */
	public static void get() throws Exception{
		  HttpRequest httpRequest = HttpRequest.get("http://localhost:8080/hsh/user/lists");
		  HttpResponse response = httpRequest.send();
		  System.out.println(new String(response.bodyBytes(),"utf-8"));
	}
	/**
	 * 发送post请求,可以发送文件
	 * @throws UnsupportedEncodingException 
	 */
	public static void post() throws UnsupportedEncodingException{
		   Map<String,Object> params=new HashMap<String,Object>();
		   params.put("platform", "jiangsu");
		   params.put("page_no", "2");
		   params.put("page_size", "4");
		   HttpRequest httpRequest = HttpRequest
			        .post("http://222.247.54.19:10030/gzticket/ticket.html");
//			        .form(params);
//			        .form(
//			            "repositoryId", "10178",
//			            "folderId", "11219",
//			            "title", "test",
//			            "description", "Upload test",
//			            "changeLog", "testing...",
//			            "file", new File("d:\\5.jpg")
//			        );
		   httpRequest.queryString("<MPAY><HEAD></HEAD><BODY></BODY></MPAY>");
		   HttpResponse httpResponse = httpRequest.send();
		   System.out.println(httpResponse);
	}
}
